home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------------------
- *
- * IPM MessageBoard AOCE Sample
- *
- * ©1992-1993 Apple Computer
- *
- -------------------------------------------------------------------------------------*/
- /*
- * commands.c -- called in response to menu commands or appleevents
- *
- * change history:
- *
- * SJF 2/12/93 1.0b1 udpate to AOCE beta seed
- * SJF 11/6/91 1.0d1 initial coding
- *
- */
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #include <string.h>
-
- #ifdef THINK_C /* MPW includes */
- #include <pascal.h>
- #endif
-
- #ifndef __OCE__
- #include <OCE.h>
- #endif
-
- #ifndef __OCEMESSAGING__
- #include <OCEMessaging.h>
- #endif
-
- #ifndef __OCEERRORS__
- #include <OCEErrors.h>
- #endif
-
- #ifndef __OCESTANDARDMAIL__
- #include <OCEStandardMail.h>
- #endif
-
- #ifndef __OCESTANDARDDIRECTORY__
- #include <OCEStandardDirectory.h>
- #endif
-
- #ifndef __OCETEMPLATES__
- #include <OCETemplates.h>
- #endif
-
- #ifdef applec
- #include <strings.h> // for c2pstr
- #endif
-
- #include "const.h"
- #include "globals.h"
- #include "utils.h"
- #include "queues.h"
- #include "statusdialog.h"
- #include "AddressOMini.h"
-
- #include "myipm.h"
- #include "GetAttribute.h"
-
-
- /*---------- init/cleanup stuff ---------------------------------------------------------*/
-
- OSErr InitIPM(void)
- {
- OSErr err;
-
- gNumMessages = 0;
- gNumDestinations = 0;
- err = GetIdentity();
- if (err!=noErr)
- return err;
- return MakeLocalQueue(&gIPMContext,&gIPMQueueRef);
- }
-
-
- void CloseIPM(void)
- {
- OSErr err;
-
- err = RemoveLocalQueue(gIPMContext,&gLocalQueue);
- if (err!=noErr)
- DoError(err);
- }
-
-
- /*---------- queue management stuff ------------------------------------------------------*/
-
-
- OSErr MakeLocalQueue(IPMContextRef *context,IPMQueueRef *queueRef)
- {
- IPMParamBlock pmBlock;
- OSErr err;
-
- *context = 0;
- *queueRef = 0;
-
- err = GetLocalQueueLocation(&gLocalQueue,kQueueName,gLocalQXtn);
- if (err!=noErr)
- return err;
-
- // create queue
-
- pmBlock.createQueuePB.queue = &gLocalQueue;
- pmBlock.createQueuePB.identity = gIdentity;
- pmBlock.createQueuePB.owner = nil;
- pmBlock.createQueuePB.ioCompletion = nil;
- IPMCreateQueue(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err!=noErr && err!=kOCEAlreadyExists)
- return err;
-
- // open context
-
- IPMOpenContext(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err!=noErr)
- return err;
- *context = pmBlock.openContextPB.contextRef;
-
- // open queue
-
- pmBlock.openQueuePB.filter = nil;
- pmBlock.openQueuePB.noteType = kIPMNewMsgMask;
-
- pmBlock.openQueuePB.notificationProc = OurIPMNotificationProc;
- pmBlock.openQueuePB.userData = SetCurrentA5();
- IPMOpenQueue(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err!=noErr)
- return err;
-
- gIPMQueueRef = pmBlock.openQueuePB.newQueueRef;
- return noErr;
- }
-
-
- OSErr RemoveLocalQueue(IPMContextRef context,OCERecipient *localQueue)
- {
- IPMParamBlock pmBlock;
- OSErr err;
-
- if (context) {
- pmBlock.closeContextPB.contextRef = context;
- pmBlock.closeContextPB.ioCompletion = nil;
- err = IPMCloseContext(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err!=noErr)
- return err;
- }
-
- pmBlock.deleteQueuePB.queue = localQueue;
- pmBlock.deleteQueuePB.identity = gIdentity;
- pmBlock.deleteQueuePB.ioCompletion = nil;
- IPMDeleteQueue(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
-
- return err;
- }
-
-
- OSErr GetLocalQueueLocation(OCERecipient *queue,StringPtr queueName,char *xtnValue)
- {
- XPPParamBlock xppPB;
- Str32 zoneName;
- StringHandle machineName;
- char *offset;
- OSErr err;
- short i;
-
- for (i=0; i<256; i++)
- xtnValue[i] = '\0';
-
- xppPB.XCALL.xppTimeout = 3;
- xppPB.XCALL.xppRetry = 4;
- xppPB.XCALL.zipBuffPtr = (Ptr)&zoneName;
- xppPB.XCALL.zipInfoField[0] = 0;
- xppPB.XCALL.zipInfoField[1] = 0;
- err = GetMyZone(&xppPB,false);
- if (err!=noErr)
- return err;
-
- machineName = GetString(kMachineNameResource);
- if (ResError()!=noErr)
- return ResError();
-
- offset = xtnValue;
- BlockMove(*machineName,offset,(*machineName)[0]+1);
- offset = offset+(*machineName)[0]+1;
-
- ReleaseResource((Handle)machineName);
-
- BlockMove(kIPMWSReceiverNBPType,offset,kIPMWSReceiverNBPType[0]+1);
- offset = (offset+kIPMWSReceiverNBPType[0]+1);
-
- BlockMove(zoneName,offset,zoneName[0]+1);
- offset = (offset+zoneName[0]+1);
-
- BlockMove(queueName,offset,queueName[0]+1);
- offset = (offset+queueName[0]+1);
-
- queue->entitySpecifier = nil; // we don't need one for direct specification
- queue->extensionType = kOCEalanXtn;
- queue->extensionValue = xtnValue;
- queue->extensionSize = StripAddress(offset)-StripAddress(xtnValue);
-
- return noErr;
- }
-
-
- /*---------- message sending stuff ------------------------------------------------------*/
-
-
- OSErr SendIPMMessage(StringPtr message,OCEPackedRecipient *packedQueue)
- {
- OSErr err,err2;
- IPMParamBlock pmBlock;
- OCERecipient queue;
- RecordID entitySpecifier;
- IPMProcHint procHint;
- short i;
- IPMMsgType msgType;
- IPMSender sender;
- RString messageTitle;
-
- // zero out proc hint
-
- for (i=0; i<sizeof(IPMProcHint); i++)
- procHint[i] = 0;
-
- // unpack destination recipient
-
- OCEUnpackDSSpec((PackedDSSpec*)packedQueue,&queue,&entitySpecifier);
-
- // get message type and sender
-
- GetOurMessageType(&msgType);
- GetOurSender(&sender);
-
- // make a new message
-
- pmBlock.newMsgPB.ioCompletion = nil;
- pmBlock.newMsgPB.recipient = &queue;
-
- pmBlock.newMsgPB.replyQueue = &gLocalQueue;
- pmBlock.newMsgPB.procHint = procHint;
-
- pmBlock.newMsgPB.msgType = &msgType;
- pmBlock.newMsgPB.identity = gIdentity;
- pmBlock.newMsgPB.sender = &sender;
- IPMNewMsg(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err!=noErr)
- return err;
-
- // make a block within that message
-
- pmBlock.newBlockPB.msgRef = pmBlock.newMsgPB.newMsgRef;
- pmBlock.newBlockPB.blockType.msgType = kAppBlockType;
- pmBlock.newBlockPB.blockType.msgCreator = kAppCreator;
- pmBlock.newBlockPB.refCon = 0;
- IPMNewBlock(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err==noErr) {
-
- // write block data
- pmBlock.writeMsgPB.offset = pmBlock.newBlockPB.startingOffset;
- pmBlock.writeMsgPB.mode = kIPMFromStart;
- pmBlock.writeMsgPB.count = message[0]+1;
- pmBlock.writeMsgPB.buffer = (Ptr)message;
- pmBlock.writeMsgPB.currentBlock = false; /* offset from beginning of main body */
- IPMWriteMsg(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
-
- }
-
- // end the message
-
- OCECToRString((char *)"message\n",smRoman,&messageTitle,kRStringMaxBytes);
-
- pmBlock.endMsgPB.deliveryNotification = 0;
- pmBlock.endMsgPB.priority = kIPMNormalPriority;
- pmBlock.endMsgPB.cancel = (err!=noErr);
- pmBlock.endMsgPB.signature = nil;
- pmBlock.endMsgPB.signatureSize = 0;
- pmBlock.endMsgPB.signatureContext = nil;
- pmBlock.endMsgPB.msgTitle = &messageTitle;
- IPMEndMsg(&pmBlock,true);
- err2 = WaitPBDone(&pmBlock);
-
- if (err!=noErr)
- return err;
- else
- return err2;
- }
-
-
-
- OSErr GetIdentityAndSaveIt (void)
- {
- OSErr err;
- SDPIdentityKind selectedKind;
-
- if ((err = SDPPromptForID (&gIdentity, "\pPlease Validate Your Identity:",
- "\pPlease Validate Your Identity:",
- "\pPlease Validate Your Identity:",
- OCEGetIndRecordType (kUserRecTypeNum),
- kSDPSpecificIdentityMask, &selectedKind, NULL, 0/*NULL*/)) != noErr)
- gIdentity = 0L;
-
- return (err);
- }
-
-
- OSErr GetNewIdentityAndSaveIt (AuthIdentity *theIdentity)
- {
- OSErr err;
- SDPIdentityKind selectedKind;
-
- if ((err = SDPPromptForID (theIdentity, "\pEnter Authentication Identity Of The Queue Creator:",
- "\pEnter Authentication Identity Of The Queue Creator:",
- "\pEnter Authentication Identity Of The Queue Creator:",
- OCEGetIndRecordType (kUserRecTypeNum),
- kSDPSpecificIdentityMask, &selectedKind, NULL, 0/*NULL*/)) != noErr)
- *theIdentity = 0L;
-
- return (err);
- }
-
-
- OSErr MyCreateQueue(StringPtr TheQName,OCEPackedRecipient **pmPackedRecipient)
- {
- OSErr err;
- IPMParamBlock IPMpb;
- OCERecipient theRecp,OwnerRecp;
- RecordID QLocRid,OwnerRid,testRecID;
- Boolean gotAddress;
- PackedDSSpecPtr packedReply,packedReply2;
- PackedRecordIDPtr testPckRecID;
- unsigned short ridSize;
- //AuthIdentity theIdentity;
- IPMEntityNameExtension TheExtn;
- unsigned long recipLength;
-
-
- gotAddress = AddressOMini(&packedReply,gTypesList,0,gIdentity,
- kEnumAllMask,"\pSelect The Server Record:",kMatchAll);
-
- if (gotAddress==false)
- return kUserCancelled;
-
- if (packedReply)
- {
- OCEUnpackDSSpec(packedReply,&theRecp,&QLocRid);
-
- TheExtn.subExtensionType = kOCEQnamXtn; // 'qnam'
- pstrcpy((Ptr)&TheExtn.u.queue.queueName,TheQName);
-
- theRecp.extensionType = kOCEentnXtn; // 'entn'
- theRecp.extensionValue = (Ptr)&TheExtn;
- theRecp.extensionSize = (TheExtn.u.queue.queueName[0] + 1) + sizeof(OSType);
-
- IPMpb.createQueuePB.queue = &theRecp;
-
- #if 0
- // let user identify the creator of the queue
- GetNewIdentityAndSaveIt (&theIdentity);
- IPMpb.createQueuePB.identity = theIdentity;
- #endif
- IPMpb.createQueuePB.identity = gIdentity;
-
- gotAddress = AddressOMini(&packedReply2,gTypesList,0,gIdentity,
- kEnumAllMask,"\pSelect The User Record Of The Queue Owner:",kMatchAll);
-
- if (gotAddress==false)
- return kUserCancelled;
-
- if (packedReply2)
- {
- OCEUnpackDSSpec(packedReply2,&OwnerRecp,&OwnerRid);
-
- OCENewRecordID(OwnerRid.rli,&OwnerRid.local,&testRecID);
- ridSize = OCEPackedRecordIDSize(&OwnerRid);
- testPckRecID = (PackedRecordIDPtr)NewPtr(ridSize);
- if ((err = MemError()) != noErr)
- return err;
- if ((err = OCEPackRecordID(&testRecID,testPckRecID,ridSize)) != noErr)
- return err;
-
- IPMpb.createQueuePB.owner = testPckRecID;
- if ((err = IPMCreateQueue(&IPMpb,false)) != noErr)
- return err;
- }
- if (testPckRecID != nil)
- DisposePtr((Ptr)testPckRecID);
-
- recipLength = OCEPackedDSSpecSize(&theRecp);
- *pmPackedRecipient = NewPtrChk(recipLength);
- if ((err=MemError())==noErr)
- OCEPackDSSpec(&theRecp,(PackedDSSpec *)*pmPackedRecipient,recipLength);
- else
- return err;
- }
-
- return err;
- }
-
- OSErr MyOpenQueue(OCERecipient *RecP)
- {
- OSErr err;
- IPMParamBlock IPMpb;
- IPMContextRef cRef;
-
-
- IPMpb.openContextPB.ioCompletion = nil;
- if ((err = IPMOpenContext(&IPMpb,false)) != noErr)
- return err;
- else
- cRef = IPMpb.openContextPB.contextRef;
-
- IPMpb.openQueuePB.ioCompletion = nil;
- IPMpb.openQueuePB.contextRef = cRef;
-
- IPMpb.openQueuePB.queue = RecP;
- IPMpb.openQueuePB.identity = gIdentity;
- IPMpb.openQueuePB.filter = nil;
-
- if ((err = IPMOpenQueue(&IPMpb,false)) != noErr)
- return err;
-
- return err;
- }
-
- OSErr OpenQueueOnRemoteMachine(StringPtr Qname,OCEPackedRecipient **pmPackedRecipient)
- {
- OSErr err;
- PackedDSSpecPtr packedReply;
- PackedRStringListHandle catTypes = nil;
- OCERecipient ipmRecipient;
- unsigned long recipLength;
- Boolean gotAddress;
- RecordID rid;
- IPMEntityNameExtension myExtn;
-
-
-
- // if ((err = GetIdentityAndSaveIt()) == noErr)
- // {
- gotAddress = AddressOMini(&packedReply,gTypesList,0,gIdentity,
- kEnumAllMask,"\pSelect The Server Record:",kMatchAll);
-
- if (gotAddress==false)
- return kUserCancelled;
-
- if (packedReply)
- {
- OCEUnpackDSSpec(packedReply,&ipmRecipient,&rid);
- ipmRecipient.extensionType = kOCEentnXtn; // 'entn'
-
- myExtn.subExtensionType = kOCEQnamXtn; // 'qnam'
- pstrcpy((Ptr)&myExtn.u.queue.queueName,Qname);
-
- ipmRecipient.extensionSize = (myExtn.u.queue.queueName[0] + 1) + sizeof(OSType);
- ipmRecipient.extensionValue = (Ptr)&myExtn;
-
- if ((err = MyOpenQueue(&ipmRecipient)) == noErr)
- {
-
- recipLength = OCEPackedDSSpecSize(&ipmRecipient);
- *pmPackedRecipient = NewPtrChk(recipLength);
- if ((err=MemError())==noErr)
- OCEPackDSSpec(&ipmRecipient,(PackedDSSpec *)*pmPackedRecipient,recipLength);
- else
- return err;
- }
-
- }
- // }
-
- return err;
- }
-
-
-
- OSErr GetSingleAttrForRecipient(OCEPackedRecipient **pmPackedRecipient,
- const OCEAttributeTypeIndex stringIndex)
- {
- OSErr err;
- PackedDSSpecPtr packedReply;
- unsigned long recipLength;
- Boolean gotAddress;
- AttributePtr theAttribute;
- OCERecipient dss;
- RecordID rid;
- IPMEntityNameExtension myExtn;
-
-
-
- gotAddress = AddressOMini(&packedReply,gTypesList/*&gTypesList*/,0,gIdentity,
- kEnumAllMask,"\pSelect The User Record:",kMatchAll);
-
- if (gotAddress==false)
- return kUserCancelled;
-
- if (packedReply)
- {
- OCEUnpackDSSpec(packedReply,&dss,&rid);
-
- if ((err = GetAttributeFromRID (&rid, OCEGetIndAttributeType (stringIndex),
- &theAttribute, gIdentity)) != noErr)
- return err;
- dss.extensionType = kOCEentnXtn; // 'entn'
-
- myExtn.subExtensionType = kOCEAttrXtn; // 'attr'
- OCECopyRString((RStringPtr)&theAttribute->attributeType,(RStringPtr)OCEGetIndAttributeType(stringIndex),kAttributeTypeMaxBytes);
-
- // #################
- dss.extensionSize = sizeof(ProtoRString) + theAttribute->attributeType.dataLength + sizeof(OSType);
- dss.extensionValue = (Ptr)&myExtn;
-
- recipLength = OCEPackedDSSpecSize(&dss);
- *pmPackedRecipient = NewPtrChk(recipLength);
- if ((err=MemError())==noErr)
- OCEPackDSSpec(&dss,(PackedDSSpec *)*pmPackedRecipient,recipLength);
-
- DisposPtr((Ptr)packedReply);
-
- }
-
- return err;
- }
-
-
-
-
-
-
- OSErr GetIPMDestination(OCEPackedRecipient **pmPackedRecipient)
- {
- PackedDSSpecPtr packedReply;
- OSErr err;
- RString addressCategory;
- unsigned short numTypes;
- PackedRStringListHandle catTypes;
- RString *typeList[kMaxPathParts];
- unsigned char hState;
- OCERecipient *ipmRecipient;
- char newXtnValue[256];
- unsigned long newXtnLength,recipLength;
- SMPRecipientDescriptorPtr recipList,freeRecip;
- Boolean gotAddress;
-
- /* display address records */
-
- OCECToRString(kDETCategoryAddressItems,smRoman,&addressCategory,kRStringMaxBytes);
- err = SDPGetCategoryTypes(&addressCategory,&catTypes);
- if (err!=noErr)
- return err;
- hState = HGetState((Handle)catTypes);
- HLock((Handle)catTypes);
- numTypes = OCEUnpackPathName(*catTypes,typeList,kMaxPathParts);
-
- gotAddress = AddressOMini(&packedReply,typeList,numTypes,gIdentity,
- kEnumDistinguishedNameMask|kEnumAliasMask|kEnumDNodeMask,"\pSelect Atalk Address:",kExactMatch);
-
- HSetState((Handle)catTypes,hState);
- if (gotAddress==false)
- return kUserCancelled;
-
- if (packedReply) {
- err = SMPResolveToRecipient(packedReply,&recipList,gIdentity);
- ipmRecipient = &recipList->theAddress;
- newXtnLength = ipmRecipient->extensionSize;
- BlockMove(ipmRecipient->extensionValue,newXtnValue,newXtnLength);
- BlockMove(kQueueName,newXtnValue+newXtnLength,kQueueName[0]+1);
- newXtnLength += kQueueName[0]+1;
- ipmRecipient->extensionSize = newXtnLength;
- ipmRecipient->extensionValue = newXtnValue;
- }
-
- // pack the recipient
-
- recipLength = OCEPackedDSSpecSize(ipmRecipient);
- *pmPackedRecipient = NewPtrChk(recipLength);
- if ((err=MemError())==noErr) {
- OCEPackDSSpec(ipmRecipient,(PackedDSSpec *)*pmPackedRecipient,recipLength);
- }
- DisposPtr((Ptr)packedReply);
-
- // free the resolvetorecipients result
-
- while (recipList!=nil) {
- freeRecip = recipList;
- recipList = recipList->next;
- DisposPtrChk(freeRecip->recipient);
- DisposPtrChk(freeRecip);
- }
-
- return err;
- }
-
-
- void GetDestAsString(short destNum,StringPtr destStr)
- {
- OCERecipient recipient;
- RecordID entitySpecifier;
- StringPtr displayName;
-
- OCEUnpackDSSpec((PackedDSSpec *)gDestList[destNum],&recipient,&entitySpecifier);
- displayName = OCERToPString(entitySpecifier.local.recordName);
- pstrcpy(destStr,displayName);
- }
-
-
- void r2cString(RString *rStr,char *cStr)
- {
- StringPtr pStr;
-
- pStr = OCERToPString(rStr);
- pstrcpy((StringPtr)cStr,pStr);
- p2cstr((StringPtr)cStr);
- }
-
-
- void GetOurMessageType(IPMMsgType *msgType)
- {
- msgType->format = kIPMOSFormatType;
- msgType->theType.msgOSType.msgCreator = kAppCreator;
- msgType->theType.msgOSType.msgType = kAppMessageType;
- }
-
-
- void GetOurSender(IPMSender *sender)
- {
- Str255 appName;
- Handle appParms;
- short refNum;
-
- GetAppParms(appName,&refNum,&appParms);
- OCEPToRString(appName,smSystemScript,&sender->theSender.rString,kRStringMaxBytes);
- sender->sendTag = kIPMSenderRStringTag;
- }
-
-
- OSErr GetIdentity(void)
- {
- OSErr err;
- SDPIdentityKind idKind;
- AuthGetLocalIdentityPB pBlock;
-
- err = AuthGetLocalIdentity((AuthParamBlockPtr)&pBlock,false);
-
- if (err!=noErr)
- err = SDPPromptForID(&gIdentity,nil,nil,kLocalIDPrompt,nil,kSDPLocalIdentityMask,&idKind,nil,0);
- else
- gIdentity = pBlock.theLocalIdentity;
-
- return err;
- }
-
-
-
- /*---------- message receiving stuff ------------------------------------------------------*/
-
-
- pascal void OurIPMNotificationProc(IPMQueueRef pmQ, IPMSeqNum pmSeq, IPMNotificationType noteType, unsigned long userData)
- {
- long savedA5;
- unsigned char noteTypeChar;
-
- noteTypeChar = (unsigned char) (noteType &= 0x000000ff);
- savedA5 = SetA5(userData);
- EnqueueNotification(pmQ,pmSeq,noteType);
- SetA5(savedA5);
- }
-
-
- void EnqueueNotification(IPMQueueRef pmQ, IPMSeqNum pmSeq, IPMNotificationType noteType)
- {
- MyQElemPtr qBlock;
-
- qBlock = GetUnusedQBlock();
- if (!qBlock) {
- DoError(kNoMemory);
- return;
- }
-
- qBlock->pmQ = pmQ;
- qBlock->pmSeq = pmSeq;
- qBlock->noteType = noteType;
-
- StoreCompletedQBlock(qBlock);
- }
-
-
- void ProcessNotification(MyQElemPtr qBlock)
- {
- OSErr err;
-
- err = noErr;
-
- if (qBlock->noteType==kIPMNewMsgMask)
- err = ProcessNewMessage(qBlock->pmQ,qBlock->pmSeq);
-
- if (err!=noErr)
- DoError(err);
-
- RecycleFreeQBlock(qBlock);
- }
-
-
- OSErr ProcessNewMessage(IPMQueueRef pmQ, IPMSeqNum pmSeq)
- {
- OSErr err;
- IPMParamBlock pmBlock;
- IPMMsgInfo msgInfo;
- Str255 msgBuffer;
-
- // open the message
-
- pmBlock.openMsgPB.ioCompletion = nil;
- pmBlock.openMsgPB.queueRef = pmQ;
- pmBlock.openMsgPB.sequenceNum = pmSeq;
- pmBlock.openMsgPB.exactMatch = true;
- IPMOpenMsg(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err!=noErr)
- return err;
-
- // get message header
- pmBlock.getMsgInfoPB.msgRef = pmBlock.openMsgPB.newMsgRef;
- pmBlock.getMsgInfoPB.info = &msgInfo;
- IPMGetMsgInfo(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err!=noErr)
- return BailMessageProcessing(&pmBlock,err);
-
- // get message block index
-
- pmBlock.getBlkIndexPB.blockType.msgType = kAppBlockType;
- pmBlock.getBlkIndexPB.blockType.msgCreator = kAppCreator;
- pmBlock.getBlkIndexPB.index = 1;
- pmBlock.getBlkIndexPB.startingFrom = 1;
- IPMGetBlkIndex(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err!=noErr)
- return BailMessageProcessing(&pmBlock,err);
-
- // get the message block
- pmBlock.readMsgPB.blockIndex = pmBlock.getBlkIndexPB.actualBlockIndex;
- pmBlock.readMsgPB.mode = kIPMFromStart;
- pmBlock.readMsgPB.offset = 0;
- pmBlock.readMsgPB.count = sizeof(Str255);
- pmBlock.readMsgPB.buffer = (Ptr)&msgBuffer;
- IPMReadMsg(&pmBlock,true);
- err = WaitPBDone(&pmBlock);
- if (err!=noErr)
- return BailMessageProcessing(&pmBlock,err);
-
- // add message to list
-
- if (gNumMessages!=kMaxMessages) {
- pstrcpy(gMessageList[gNumMessages],msgBuffer);
- AddItemToList(gNumMessages,kMsgListDItem);
- gNumMessages++;
- }
- else SysBeep(1); // no room in list
-
- return BailMessageProcessing(&pmBlock,err);
- }
-
-
- /* delete the message and exit with the passed in error code */
-
- OSErr BailMessageProcessing(IPMParamBlock *pmBlock,OSErr err)
- {
- OSErr err2;
-
- // delete the message
-
- pmBlock->closeMsgPB.deleteMsg = true;
- IPMCloseMsg(pmBlock,true);
- err2 = WaitPBDone(pmBlock);
-
- if (err==noErr)
- return err2;
- else
- return err;
- }
-
-